/*
 * CEnvironment.cpp
 *
 *  Created on: 11 Oct 2012
 *      Author: Mario Kleinsasser
 *		Time:	19:05:35
 */

#include "CEnvironment.h"
#include "CAnthill.h"
#include "CFood.h"
#include "CItemFactory.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

// init static variables

/* IMPORTANT set the instance pointer to 0 (NULL) on init*/
CEnvironment* CEnvironment::instance = NULL;


CEnvironment::CEnvironment(int m, int n) {
	this->curM = m;
	this->curN = n;

	this->playground = new CAreaList(this->curM,this->curN);
};

CEnvironment::~CEnvironment() {
};

CEnvironment* CEnvironment::getInstance(int m, int n) {
	if (!instance) {
		/* if no CEnvironment instance exists, create the one and only */
		instance = new CEnvironment(m, n);
	}

/*	if(m != 0 && n != 0){
		// no evaluation of the size if 0 in parameter
		if(curM <= m && curN <= n){
			// expand if actual size not equal the wanted size
			//TODO: Expand-method
		}
	}
*/


		/* initialize the playground */
		//instance->playground = new CAreaList(m, n);

		/*
		 * Use the CItemFactory to create Anthill and Food
		 * This includes dynamic cast derived-to-base
		 * Later include exception
		 */

		//CItemFactory *myGameFactory = new CItemFactory();

		//myGameFactory->newItem("anthill");
		//myGameFactory->newItem("food");

	/* return the existing object */
	return (instance);
}

void CEnvironment::destroy() {

	//TODO: Delete the <list> of areas

	/* delete the object */
	delete instance;

	/* set back instance count */
	instance = NULL;
}


void CEnvironment::actAll() {
	//TODO: call act all on playground element items, currently only print
	this->playground->actAll();

}



